package com.ocean.recommendationserver.realtimerecommend.controller;


import com.alibaba.fastjson.JSONObject;
import com.ocean.recommendationserver.realtimerecommend.constant.MovieConstant;
import com.ocean.recommendationserver.realtimerecommend.entity.Rating;
import com.ocean.recommendationserver.realtimerecommend.result.Result;
import com.ocean.recommendationserver.realtimerecommend.service.IRatingService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ocean
 * @since 2021-07-18
 */
@RestController
@RequestMapping("/rating")
public class RatingController {

    private static Logger logger = Logger.getLogger(RatingController.class.getName());

    @Autowired
    private IRatingService ratingService;

    @PostMapping("/ratingForAMovie")
    public Result<String> ratingForAMovie(@RequestBody JSONObject params){
        Rating newRating = ratingService.ratingForAMovie(params.getInteger("uid"), params.getInteger("mid"), params.getDouble("rating"));
        logger.info(MovieConstant.MOVIE_RATING_PREFIX + ":" + newRating.getUid() +"|"+ newRating.getMid()+"|"+ newRating.getScore() +"|"+ newRating.getTimestamp());

        return Result.success("打分成功");
    }
}
